<?php

namespace app\api\controller\xyvenue;

use app\common\controller\Api;
use app\api\model\xyvenue\Config;
use app\api\model\xyvenue\store\Store;
use app\api\model\xyvenue\recharge\Recharge;
use app\api\model\xyvenue\Notice;
use app\api\model\xyvenue\Level;
use think\Db;

/**
 * 通用接口
 */
class Machine extends Api
{
	protected $noNeedLogin = ['*'];
	protected $noNeedRight = ['*'];
	
	
	
	//门禁
	public function setVideo(){
	    
	    $params = $this->request->post();
	    $tablename = 'xyvenue_video';
	    
	     // 检查记录是否存在
        $existingRecord = Db::name($tablename)
                            ->select();
        $responseData = array();
        foreach($existingRecord as $key=>$Record){                    
        // 数据
            $responseData[] = [
                'id' => $Record['machine_id'],
                '@id' => '网卡MAC地址作为ID,每个设备都不一样',
                'msg' => 'setVideo',
                '@msg' => '设置积分',
                'x' => $Record['x'],
                '@x' => 'x坐标',
                 'y' => $Record['y'],
                '@y' => 'y坐标',
                 'score' => $Record['score'],
                '@score' => '积分',
            ];
        }

        // 返回JSON格式的数据
        return json_encode($responseData,JSON_UNESCAPED_UNICODE);      
	}
	
	
	//门禁
	public function setEntranceGuard(){
	    
	    $params = $this->request->post();
	    $tablename = 'xyvenue_room';
	    
	     // 检查记录是否存在
        $existingRecord = Db::name($tablename)
                            ->where('machine_id','4A13E4F97975')
                            ->find();
        // 数据
        $responseData = [
            'id' => $existingRecord['machine_id'],
            '@id' => '网卡MAC地址作为ID,每个设备都不一样',
            'msg' => 'setEntranceGuard',
            '@msg' => '设置门禁',
            'switch' => $existingRecord['switch'],
            '@switch' => 'off:关 on:开',
        ];

        // 返回JSON格式的数据
        return json_encode($responseData,JSON_UNESCAPED_UNICODE);      
	}
	
	
	//灯
	public function setLight(){
	    
	    $params = $this->request->post();
	    $tablename = 'xyvenue_light';
	    
	     // 检查记录是否存在
        $existingRecord = Db::name($tablename)
                            ->where('machine_id','4A13E4F97975')
                            ->find();
        // 数据
        $responseData = [
            'id' => $existingRecord['machine_id'],
            '@id' => '网卡MAC地址作为ID,每个设备都不一样',
            'msg' => 'setLight',
            '@msg' => '设置灯光',
            'state' => $existingRecord['state'],
            '@state' => '总共10个灯，每个bit代表一个灯的状态，0x0101表示第1个和第9个灯亮，其他的灯灭',
        ];

        // 返回JSON格式的数据
        return json_encode($responseData,JSON_UNESCAPED_UNICODE);      
	}
	
	//空调
	public function setAirconditioner(){
	    
	    $params = $this->request->post();
	    $tablename = 'xyvenue_air';
	    
	     // 检查记录是否存在
        $existingRecord = Db::name($tablename)
                            ->where('machine_id','4A13E4F97975')
                            ->find();
        // 数据
        $responseData = [
            'id' => $existingRecord['machine_id'],
            '@id' => '网卡MAC地址作为ID,每个设备都不一样',
            'msg' => 'setAirconditioner',
            '@msg' => '设置空调参数',
            "switch"=>"off",
        	"@switch"=>"off:关 on:开",
        	"mode"=>"auto",
            "@mode"=>"auto: 自动 cool: 制冷 dry: 除湿 fan: 送风 heat: 制热",
        	"T"=>25.5,
        	"@T"=>"温度，浮点数",
        	"fan"=>3,
        	"@fan"=>"风速，整数",
        ];

        // 返回JSON格式的数据
        return json_encode($responseData,JSON_UNESCAPED_UNICODE);      
	}
	

	//空调
	public function setMachine(){
	    
	    $params = $this->request->post();
	    $tablename = 'xyvenue_setting';
	    
	     // 检查记录是否存在
        $existingRecord = Db::name($tablename)
                            ->where('machine_id','4A13E4F97975')
                            ->find();
        // 数据
        $responseData = [
            'id' => $existingRecord['machine_id'],
            '@id' => '网卡MAC地址作为ID,每个设备都不一样',
            "msg"=>"ctrlMachine",
            "@msg"=>"设置网球机",
        	"en"=>$existingRecord['enable'],
            "@en"=>"0：启动发球，1：停止发球",
            "mode"=>$existingRecord['mode'],
            "@mode"=>"1为定点发球,2为左右发球,3为前后发球,4为全场随机球,5为程序球",
            "balls"=>$existingRecord['islock'],
            "lock"=>$existingRecord['balls'],
            "positionX"=>$existingRecord['positionX'],
             "@positionX"=>"上下位置",
            "positionY"=>$existingRecord['positionY'],
             "@positionY"=>"左右位置",
            "@lock"=>"0：未锁定，1：锁定",
            "@balls"=>"30：30球，50：50球",
            "value"=>0x1112,
            "@value"=>"有些模式需要填入数值，目前还没有明白，等测试好了再补充",
        ];

        // 返回JSON格式的数据
        return json_encode($responseData,JSON_UNESCAPED_UNICODE);      
	}

}